package com.unei.httpclient;

import org.apache.http.Header;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.StringReader;

/*
 * Created by sunlei on 2015/4/16.
 */
public class HttpClientFirstSample {
    public static void main(String[] args) throws IOException {
        CloseableHttpClient httpClient= HttpClients.createDefault();
        HttpGet httpGet=new HttpGet("http://www.csdn.net");
        CloseableHttpResponse response=httpClient.execute(httpGet);
        System.out.println(response.getStatusLine());
        System.out.println(response.getProtocolVersion());
//        EntityUtils.consume(response.getEntity());
//        InputStream ins=response.getEntity().getContent();
//        byte[] buffer=new byte[1024];
//        int cnt=0;
//        while((cnt=ins.read(buffer,0,1024))!=-1){
//            System.out.println(new String(buffer,0,cnt));
//        }
        Header[] headers=response.getAllHeaders();
        for(Header header:headers){
            System.out.println(header.toString());
        }
        response.close();
    }
}
